﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using RushTracker.Core.Models;

namespace RushTracker.Core.Security
{
    public class RushTrackerPrincipal : IPrincipal
    {
        private User _user;

        public RushTrackerPrincipal(User u)
        {
            if (!u.IsAuthenticated)
            {
                throw new ArgumentException("User provided must be authenticated");
            }

            this._user = u;
        }

        public IIdentity Identity
        {
            get { return this._user; }
        }

        public bool IsInRole(string role)
        {
            return (this._user.Roles.FirstOrDefault(r => r.Name == role) != null);
        }
    }
}
